/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.pizzaria.view;

import br.com.pizzaria.bean.PrecoProdutoBean;
import br.com.pizzaria.controller.PedidoController;
import br.com.pizzaria.controller.PrecoProdutoController;
import br.com.pizzaria.controller.ProdutoController;
import br.com.pizzaria.model.ProdutoModel;
import br.com.pizzaria.bean.FornecedorBean;
import br.com.pizzaria.bean.ItemNotaFiscalEntradaBean;
import br.com.pizzaria.bean.ProdutoBean;
import br.com.pizzaria.bean.TipoProdutoBean;
import br.com.pizzaria.model.PedidoModel;
import br.com.pizzaria.util.CentralizarForm;
import br.com.pizzaria.util.ConectaBanco;
import br.com.pizzaria.util.Global;
import br.com.pizzaria.util.ValidaCNPJ;
import br.com.pizzaria.util.ValidaCPF;
import br.com.pizzaria.util.VerificarData;
import java.awt.event.KeyEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Jaime
 */
public class PedidoCompraView extends javax.swing.JInternalFrame {

    ComboBoxModel<PrecoProdutoBean> modeloComboProd;

    MaskFormatter formatoNascimento;
    ComboBoxModel<TipoProdutoBean> modeloTipoProd;
    ComboBoxModel<TipoProdutoBean> modeloTipoPizza;
    List<TipoProdutoBean> listaTipoProd;
    List<TipoProdutoBean> listaTipoPizza;
    ProdutoController produtoController;
    List<ProdutoBean> listaProduto;
    List<FornecedorBean> listaFornecedor;
    ComboBoxModel<ProdutoBean> modeloPizzaInteira;
    List<ProdutoBean> listaPizzaInteira;
    ComboBoxModel<ProdutoBean> modeloPizzaSabor1;
    List<ProdutoBean> listaPizzaSabor1;
    ComboBoxModel<ProdutoBean> modeloPizzaSabor2;
    List<ProdutoBean> listaPizzaSabor2;
    ComboBoxModel<ProdutoBean> modeloBorda;
    List<ProdutoBean> listaBorda;
    IngredientesPizzaView ingredienteV;
    PedidoController entregaPedidoController;
    PrecoProdutoController precoProdutoController;
    DefaultTableModel modeloDeTabela;
    DecimalFormat decimalFormato;
    List<ItemNotaFiscalEntradaBean> listaDeItens;
    ComboBoxModel<ProdutoBean> modeloProduto;
    ComboBoxModel<FornecedorBean> modeloForncedor;

    List<FornecedorBean> listaFornec;

    /**
     * Creates new form NotaFiscalEntradaView
     */
    public PedidoCompraView() {

        initComponents();

        precoProdutoController = new PrecoProdutoController();
        produtoController = new ProdutoController();
        modeloTipoProd = cbTipo.getModel();
        modeloDeTabela = (DefaultTableModel) tblProduto.getModel();
        decimalFormato = new DecimalFormat("0.00");
        listaDeItens = new ArrayList<>();
        modeloProduto = cbProduto.getModel();
        txtDtemissao.setText(VerificarData.retornoDeDataAtual());
        txtUnidadeItem.setEditable(false);
        modeloTipoProd = cbTipo.getModel();
        modeloProduto = cbProduto.getModel();
        modeloForncedor = cbFornecedor.getModel();
        //txtDtEmissao.setText(VerificarData.retornoDeDataAtual());
        // modeloDeTabela = (DefaultTableModel) tblProduto.getModel();
        //decimalFormato = new DecimalFormat("0.00");
        //listaDeItens = new ArrayList<>();
        // txtNumNotaFiscal.setDocument(new LimiteDigitos(10));
        // txtSerie.setDocument(new LimiteDigitos(3));
        populaTipoProduto();
        populaFornecedor();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txtObs = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        lbl_data2 = new javax.swing.JLabel();
        try{        formatoNascimento = new MaskFormatter("##/##/####");    }catch (Exception Erro){      JOptionPane.showMessageDialog(null, "Data inválida", "ERRO DE FORMATAÇÃO", 0);  }
        txtDtemissao = new JFormattedTextField(formatoNascimento);
        lbl_data6 = new javax.swing.JLabel();
        txtCNPJ = new javax.swing.JTextField();
        lbl_data7 = new javax.swing.JLabel();
        cbFornecedor = new javax.swing.JComboBox();
        lblValor3 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();
        lblValor4 = new javax.swing.JLabel();
        txtValorDes = new javax.swing.JTextField();
        lblValor5 = new javax.swing.JLabel();
        txtValorNf = new javax.swing.JTextField();
        lbl_data11 = new javax.swing.JLabel();
        jFormaPagamento = new javax.swing.JComboBox();
        lbl_data12 = new javax.swing.JLabel();
        txtParc = new javax.swing.JTextField();
        lbl_data13 = new javax.swing.JLabel();
        jtipoPedido = new javax.swing.JComboBox();
        lbl_data10 = new javax.swing.JLabel();
        jCondPagamento = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        txtUnidadeItem = new javax.swing.JTextField();
        lblValor11 = new javax.swing.JLabel();
        txtRefProdItem = new javax.swing.JTextField();
        txtTotalNotaItem = new javax.swing.JTextField();
        lblValor6 = new javax.swing.JLabel();
        btnAdicionar = new javax.swing.JButton();
        lblValor7 = new javax.swing.JLabel();
        btnRemover = new javax.swing.JButton();
        txtQtdeItem = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblProduto = new javax.swing.JTable();
        lblValor8 = new javax.swing.JLabel();
        lbl_data1 = new javax.swing.JLabel();
        txtValorUnitarioItem = new javax.swing.JTextField();
        cbTipo = new javax.swing.JComboBox();
        lblValor9 = new javax.swing.JLabel();
        lbl_data8 = new javax.swing.JLabel();
        txtTotalItem = new javax.swing.JTextField();
        cbProduto = new javax.swing.JComboBox();
        lblValor10 = new javax.swing.JLabel();
        lbl_data9 = new javax.swing.JLabel();
        txtDescontoItem = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("PEDIDO DE COMPRA");
        setPreferredSize(new java.awt.Dimension(680, 680));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Pedido"));

        jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel1.setText("Observação:");

        lbl_data2.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data2.setText("Dt. Emissão:");

        txtDtemissao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDtemissaoKeyTyped(evt);
            }
        });

        lbl_data6.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data6.setText("CNPJ Fornec:");

        txtCNPJ.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCNPJKeyTyped(evt);
            }
        });

        lbl_data7.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data7.setText("Nome Fornecedor:");

        cbFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbFornecedorActionPerformed(evt);
            }
        });

        lblValor3.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor3.setText("Vlr. Total:");

        txtTotal.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtTotalFocusLost(evt);
            }
        });
        txtTotal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTotalKeyTyped(evt);
            }
        });

        lblValor4.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor4.setText("Vlr. Desc:");

        txtValorDes.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtValorDesFocusLost(evt);
            }
        });
        txtValorDes.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtValorDesKeyTyped(evt);
            }
        });

        lblValor5.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor5.setText("Vlr. NF:");

        txtValorNf.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtValorNfFocusLost(evt);
            }
        });
        txtValorNf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtValorNfKeyTyped(evt);
            }
        });

        lbl_data11.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data11.setText("Forma Pagto.:");

        jFormaPagamento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Escolha forma de Pagamento", "Dinheiro", "Cartão de Crédito", "Cartão de Débito" }));
        jFormaPagamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFormaPagamentoActionPerformed(evt);
            }
        });

        lbl_data12.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data12.setText("Parcelas:");

        txtParc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtParcActionPerformed(evt);
            }
        });
        txtParc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtParcKeyTyped(evt);
            }
        });

        lbl_data13.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data13.setText("Tipo Pedido");

        jtipoPedido.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tipo de Pedido", "Pedido", "Cotação" }));
        jtipoPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtipoPedidoActionPerformed(evt);
            }
        });

        lbl_data10.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data10.setText("Cond. Pagto.:");

        jCondPagamento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Escolha cond/Pagamento", "À Vista", "Parcelado" }));
        jCondPagamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCondPagamentoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtObs)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(lbl_data13))
                        .addGap(0, 523, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jtipoPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblValor3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblValor4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtValorDes, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                                .addComponent(lblValor5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbl_data2)
                                    .addComponent(txtDtemissao, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jFormaPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lbl_data11, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbl_data10)
                                    .addComponent(jCondPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(19, 19, 19)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtValorNf, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(lbl_data12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtParc, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_data6)
                            .addComponent(txtCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lbl_data7)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(cbFornecedor, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_data6)
                    .addComponent(lbl_data7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lbl_data2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtDtemissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lbl_data11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jFormaPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lbl_data12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtParc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lbl_data10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCondPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(4, 4, 4)
                .addComponent(lbl_data13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblValor3, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblValor4, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtValorDes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblValor5, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtValorNf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jtipoPedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtObs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Itens"));

        txtUnidadeItem.setEditable(false);

        lblValor11.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor11.setText("Vlr. NF.:");

        txtRefProdItem.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtRefProdItemFocusLost(evt);
            }
        });
        txtRefProdItem.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtRefProdItemKeyTyped(evt);
            }
        });

        txtTotalNotaItem.setEditable(false);
        txtTotalNotaItem.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtTotalNotaItemFocusLost(evt);
            }
        });
        txtTotalNotaItem.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTotalNotaItemKeyTyped(evt);
            }
        });

        lblValor6.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor6.setText("Ref. Produto");

        btnAdicionar.setText("Adicionar");
        btnAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarActionPerformed(evt);
            }
        });

        lblValor7.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor7.setText("Qtde:");

        btnRemover.setText("Remover");
        btnRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverActionPerformed(evt);
            }
        });

        txtQtdeItem.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtQtdeItemFocusLost(evt);
            }
        });
        txtQtdeItem.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtQtdeItemKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtQtdeItemKeyTyped(evt);
            }
        });

        tblProduto.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Item", "Produto", "U.Med.", "Qtde", "Vlr.Unit.", "Vlr.Total", "Vlr.Desc", "Vlr.NF."
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblProduto.getTableHeader().setReorderingAllowed(false);
        tblProduto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblProdutoMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(tblProduto);

        lblValor8.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor8.setText("Vlr. Unit.:");

        lbl_data1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data1.setText("Tipo Produto:");

        txtValorUnitarioItem.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtValorUnitarioItemFocusLost(evt);
            }
        });
        txtValorUnitarioItem.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtValorUnitarioItemKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtValorUnitarioItemKeyTyped(evt);
            }
        });

        cbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecionar Tipo Produto" }));
        cbTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTipoActionPerformed(evt);
            }
        });

        lblValor9.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor9.setText("Vlr. Total:");

        lbl_data8.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data8.setText("Produto:");

        txtTotalItem.setEditable(false);
        txtTotalItem.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtTotalItemFocusLost(evt);
            }
        });
        txtTotalItem.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTotalItemKeyTyped(evt);
            }
        });

        cbProduto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecionar Produto" }));
        cbProduto.setEnabled(false);
        cbProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbProdutoActionPerformed(evt);
            }
        });

        lblValor10.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lblValor10.setText("Vlr. Desc.:");

        lbl_data9.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        lbl_data9.setText("Unid. Med.");

        txtDescontoItem.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtDescontoItemFocusLost(evt);
            }
        });
        txtDescontoItem.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDescontoItemKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDescontoItemKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblValor6)
                            .addComponent(txtRefProdItem, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblValor7)
                            .addComponent(txtQtdeItem, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblValor8)
                            .addComponent(txtValorUnitarioItem, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblValor9)
                            .addComponent(txtTotalItem, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtDescontoItem)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(lblValor10)
                                        .addGap(0, 6, Short.MAX_VALUE)))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblValor11)
                                    .addComponent(txtTotalNotaItem, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(btnAdicionar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnRemover))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lbl_data1)
                            .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_data8)
                            .addComponent(cbProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(lbl_data9)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(txtUnidadeItem))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lbl_data9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtUnidadeItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lbl_data8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lbl_data1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblValor6, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtRefProdItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblValor7, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtQtdeItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblValor8, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtValorUnitarioItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lblValor9, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtTotalItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblValor10, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblValor11, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDescontoItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtTotalNotaItem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnRemover)
                    .addComponent(btnAdicionar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jButton3.setText("Excluir");

        jButton4.setText("Salvar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Fechar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton5)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 93, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4)
                    .addComponent(jButton5))
                .addGap(53, 53, 53))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtDtemissaoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDtemissaoKeyTyped
        String caracteres = "0987654321";

        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_txtDtemissaoKeyTyped

    private void txtCNPJKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCNPJKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCNPJKeyTyped

    private void txtTotalFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTotalFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTotalFocusLost

    private void txtTotalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTotalKeyTyped
        String caracteres = "0987654321,.";

        if (!caracteres.contains(evt.getKeyChar() + "")) {

            evt.consume();

        }
    }//GEN-LAST:event_txtTotalKeyTyped

    private void txtValorDesFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtValorDesFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_txtValorDesFocusLost

    private void txtValorDesKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValorDesKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtValorDesKeyTyped

    private void txtValorNfFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtValorNfFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_txtValorNfFocusLost

    private void txtValorNfKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValorNfKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtValorNfKeyTyped

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        if (validaCamposNotaFiscal()) {
            if (cadastraPedido()) {
                this.dispose();
                PedidoCompraView notaFiscalEntradaV = new PedidoCompraView();
                Global.principal.Desktop.add(notaFiscalEntradaV);
                CentralizarForm.centralizaForm(notaFiscalEntradaV);
                notaFiscalEntradaV.setVisible(true);
            }
        }        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void txtParcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtParcActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtParcActionPerformed

    private void txtParcKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtParcKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtParcKeyTyped

    private void cbFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbFornecedorActionPerformed

        txtCNPJ.setText(((FornecedorBean) cbFornecedor.getSelectedItem()).getPfj());
        validaCNPJCPF();


    }//GEN-LAST:event_cbFornecedorActionPerformed

    private void txtRefProdItemFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtRefProdItemFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_txtRefProdItemFocusLost

    private void txtRefProdItemKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRefProdItemKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtRefProdItemKeyTyped

    private void txtTotalNotaItemFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTotalNotaItemFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTotalNotaItemFocusLost

    private void txtTotalNotaItemKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTotalNotaItemKeyTyped
        // TODO add your handling code here:
        String caracteres = "0987654321.,";

        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_txtTotalNotaItemKeyTyped
    int item;
    private void btnAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarActionPerformed
        // TODO add your handling code here:
        if (validaCamposItem()) { //voce vai ter que copar os metodos que fiz para cá ok
            adicionaItemPedido();
            modeloDeTabela.addRow(new Object[]{item, cbProduto.getSelectedItem(), txtUnidadeItem.getText(), txtQtdeItem.getText(), decimalFormato.format(Double.parseDouble(txtValorUnitarioItem.getText().replace(",", "."))), txtTotalItem.getText(), txtDescontoItem.getText().isEmpty() ? 0 : decimalFormato.format(Double.parseDouble(txtDescontoItem.getText().replace(",", "."))), txtTotalNotaItem.getText()});
            cbTipo.setSelectedIndex(0);
            calculaTotal();
        }
    }//GEN-LAST:event_btnAdicionarActionPerformed

    private void btnRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverActionPerformed
        // TODO add your handling code here:
        int linha = tblProduto.getSelectedRow();
        if (linha < 0) {
            JOptionPane.showMessageDialog(null, "Selecione um item na lista para remover", "ERRO", 0, new ImageIcon("imagens/cancelar.png"));
        } else {
            switch (JOptionPane.showConfirmDialog(null, "Remover Item " + listaDeItens.get(linha), "Remover item de pedido", JOptionPane.YES_NO_OPTION)) {
                case 0:
                    modeloDeTabela.removeRow(linha);
                    listaDeItens.remove(linha);
                    calculaTotal();
                    break;
            }
        }
    }//GEN-LAST:event_btnRemoverActionPerformed

    private void txtQtdeItemFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtQtdeItemFocusLost
        // TODO add your handling code here:
        txtTotalItem.setText("");
        txtDescontoItem.setText("");
        txtTotalNotaItem.setText("");
        calculaTotalItem();
    }//GEN-LAST:event_txtQtdeItemFocusLost

    private void txtQtdeItemKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtQtdeItemKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtTotalItem.setText("");
            txtDescontoItem.setText("");
            txtTotalNotaItem.setText("");
            calculaTotalItem();
        }
    }//GEN-LAST:event_txtQtdeItemKeyPressed

    private void txtQtdeItemKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtQtdeItemKeyTyped
        // TODO add your handling code here:
        String caracteres = "0987654321.,";

        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_txtQtdeItemKeyTyped

    private void tblProdutoMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblProdutoMousePressed

    }//GEN-LAST:event_tblProdutoMousePressed

    private void txtValorUnitarioItemFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtValorUnitarioItemFocusLost
        // TODO add your handling code here:
        txtTotalItem.setText("");
        txtDescontoItem.setText("");
        txtTotalNotaItem.setText("");
        calculaTotalItem();
    }//GEN-LAST:event_txtValorUnitarioItemFocusLost

    private void txtValorUnitarioItemKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValorUnitarioItemKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtTotalItem.setText("");
            txtDescontoItem.setText("");
            txtTotalNotaItem.setText("");
            calculaTotalItem();
        }
    }//GEN-LAST:event_txtValorUnitarioItemKeyPressed

    private void txtValorUnitarioItemKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValorUnitarioItemKeyTyped
        // TODO add your handling code here:
        String caracteres = "0987654321.,";

        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_txtValorUnitarioItemKeyTyped

    private void cbTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTipoActionPerformed
        if (cbTipo.getSelectedIndex() > 0) {
            limpaCamposItens();
            cbProduto.removeAllItems();
            populaListaProduto();
            cbProduto.setEnabled(true);

        } else {
            cbProduto.setEnabled(false);
            cbProduto.setSelectedIndex(0);
            limpaCamposItens();
        }
    }//GEN-LAST:event_cbTipoActionPerformed

    private void txtTotalItemFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTotalItemFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTotalItemFocusLost

    private void txtTotalItemKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTotalItemKeyTyped
        // TODO add your handling code here:
        String caracteres = "0987654321.,";

        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_txtTotalItemKeyTyped

    private void cbProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProdutoActionPerformed
        if (cbProduto.getSelectedIndex() > 0) {
            limpaCamposItens();

            txtUnidadeItem.setText(((ProdutoBean) modeloProduto.getSelectedItem()).getUnidadeMedida());

            //JOptionPane.showMessageDialog(null,((ProdutoBean) modeloProduto.getSelectedItem()).getUnidadeMedida() );
        } else {

            limpaCamposItens();
        }
    }//GEN-LAST:event_cbProdutoActionPerformed

    private void jtipoPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtipoPedidoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtipoPedidoActionPerformed

    private void jFormaPagamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormaPagamentoActionPerformed

        if (jFormaPagamento.getSelectedItem().equals("Dinheiro") || jFormaPagamento.getSelectedItem().equals("Cartão de Débito")) {

            jCondPagamento.setSelectedIndex(1);

        } else if (jFormaPagamento.getSelectedItem().equals("Cartão de Crédito")) {

            jCondPagamento.setSelectedIndex(2);

        } else {

            jCondPagamento.setSelectedIndex(0);
        }
    }//GEN-LAST:event_jFormaPagamentoActionPerformed

    private void jCondPagamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCondPagamentoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCondPagamentoActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        switch (JOptionPane.showConfirmDialog(null, "Deseja sair", "Sair", JOptionPane.YES_NO_OPTION)) {
            case 0:
                this.dispose();
                break;
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void txtDescontoItemKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescontoItemKeyTyped
        // TODO add your handling code here:
        String caracteres = "0987654321.,";

        if (!caracteres.contains(evt.getKeyChar() + "")) {
            evt.consume();
        }
    }//GEN-LAST:event_txtDescontoItemKeyTyped

    private void txtDescontoItemKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescontoItemKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            calculaTotalNotaItem();
        }
    }//GEN-LAST:event_txtDescontoItemKeyPressed

    private void txtDescontoItemFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDescontoItemFocusLost
        // TODO add your handling code here:
        calculaTotalNotaItem();
    }//GEN-LAST:event_txtDescontoItemFocusLost
    public void populaTipoProduto() {
        ProdutoModel produtoModel = new ProdutoModel();

        listaTipoProd = new ArrayList<>();
        produtoModel.populaListaTipoProduto(listaTipoProd);
        for (TipoProdutoBean tipoProdutoBeans : listaTipoProd) {
            cbTipo.addItem(tipoProdutoBeans);
        }
    }

    public void populaListaProduto() {

        if (cbTipo.getSelectedIndex() > 0) {
            listaProduto = new ArrayList<>();
            pesquisaProdutos(((TipoProdutoBean) modeloTipoProd.getSelectedItem()).getCodigo(), listaProduto);
            cbProduto.addItem("Selecionar Produto");

            for (ProdutoBean prdutoBeans : listaProduto) {
                cbProduto.addItem(prdutoBeans);
            }

        } else {

            cbProduto.setSelectedIndex(0);
        }

    }

    public void populaFornecedor() {

        String SQLSelection = "SELECT\n" //mexemos no 
                + "  `for_nome`,\n"
                + "  `for_cod_pfj`,\n"
                + "  `for_id_fornec`\n"
                + "  \n"
                + "FROM `pizzaria`.`fornecedor`\n"
                + "WHERE `for_status` ='Ativo' ;";

        try (PreparedStatement pstm = ConectaBanco.getConnection().prepareStatement(SQLSelection)) {

            ResultSet rs = pstm.executeQuery();

            while (rs.next()) {
                FornecedorBean novo = new FornecedorBean();

                novo.setNome(rs.getString("for_nome"));
                novo.setPfj(rs.getString("for_cod_pfj"));
                novo.setCodigo(rs.getInt("for_id_fornec"));

                cbFornecedor.addItem(novo);
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Impossível Carregar Lista " + ex, "Erro de SQL ", 0, new ImageIcon("imagens/cancelar.png"));
        }

    }

    public void capituraCnpj() {

        String name = ((FornecedorBean) cbFornecedor.getSelectedItem()).getPfj();// aqui o erro

        String SQLSelection = "SELECT \n"
                + "  `for_cod_pfj` \n"
                + "FROM\n"
                + "  `pizzaria`.`fornecedor` \n"
                + "WHERE `for_nome` = '" + name + "' and for_status='Ativo';\n"
                + "";

        try (PreparedStatement pstm = ConectaBanco.getConnection().prepareStatement(SQLSelection)) {

            ResultSet rs = pstm.executeQuery();
            if (rs.next()) {
                txtCNPJ.setText(rs.getString("for_cod_pfj`"));
            }
        } catch (SQLException ex) {
            // tentei colocar a varial name... depois meu nome  como agora.. mas não tras de jeito nehum.... não consegui vazer no padrão de lista como vc faz =(
            JOptionPane.showMessageDialog(null, "Impossível Carregar Lista " + ex, "Erro de SQL ", 0, new ImageIcon("imagens/cancelar.png"));
        }

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdicionar;
    private javax.swing.JButton btnRemover;
    private javax.swing.JComboBox cbFornecedor;
    private javax.swing.JComboBox cbProduto;
    private javax.swing.JComboBox cbTipo;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jCondPagamento;
    private javax.swing.JComboBox jFormaPagamento;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jtipoPedido;
    private javax.swing.JLabel lblValor10;
    private javax.swing.JLabel lblValor11;
    private javax.swing.JLabel lblValor3;
    private javax.swing.JLabel lblValor4;
    private javax.swing.JLabel lblValor5;
    private javax.swing.JLabel lblValor6;
    private javax.swing.JLabel lblValor7;
    private javax.swing.JLabel lblValor8;
    private javax.swing.JLabel lblValor9;
    private javax.swing.JLabel lbl_data1;
    private javax.swing.JLabel lbl_data10;
    private javax.swing.JLabel lbl_data11;
    private javax.swing.JLabel lbl_data12;
    private javax.swing.JLabel lbl_data13;
    private javax.swing.JLabel lbl_data2;
    private javax.swing.JLabel lbl_data6;
    private javax.swing.JLabel lbl_data7;
    private javax.swing.JLabel lbl_data8;
    private javax.swing.JLabel lbl_data9;
    private javax.swing.JTable tblProduto;
    private javax.swing.JTextField txtCNPJ;
    private javax.swing.JTextField txtDescontoItem;
    private javax.swing.JTextField txtDtemissao;
    private javax.swing.JTextField txtObs;
    private javax.swing.JTextField txtParc;
    private javax.swing.JTextField txtQtdeItem;
    private javax.swing.JTextField txtRefProdItem;
    private javax.swing.JTextField txtTotal;
    private javax.swing.JTextField txtTotalItem;
    private javax.swing.JTextField txtTotalNotaItem;
    private javax.swing.JTextField txtUnidadeItem;
    private javax.swing.JTextField txtValorDes;
    private javax.swing.JTextField txtValorNf;
    private javax.swing.JTextField txtValorUnitarioItem;
    // End of variables declaration//GEN-END:variables

    public boolean validaCamposItem() {
        if (cbProduto.getSelectedIndex() <= 0) {
            JOptionPane.showMessageDialog(null, "Selecione um produto!");
            cbProduto.requestFocus();
            return false;
        }
        if (txtQtdeItem.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Campo Quantidade não pode ser vazio!");
            txtQtdeItem.requestFocus();
            return false;
        }
        if (txtValorUnitarioItem.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Campo Valor Unitário não pode ser vazio!");
            txtValorUnitarioItem.requestFocus();
            return false;
        }
        if (txtTotalItem.getText().isEmpty()) {
            return false;

        }
        if (txtTotalNotaItem.getText().isEmpty()) {
            return false;
        }
        return true;
    }

    public void calculaTotal() {
        double totalNotaFiscal = 0;
        for (ItemNotaFiscalEntradaBean listaDeIten : listaDeItens) {
            totalNotaFiscal += listaDeIten.getPrecoTotalNotaFiscalItem();
        }

        txtTotalItem.setText(decimalFormato.format(totalNotaFiscal).replace(",", "."));
        txtTotalNotaItem.setText(decimalFormato.format(totalNotaFiscal).replace(",", "."));
        txtDescontoItem.setText("");
        txtTotal.setText(txtTotalItem.getText());
        txtValorDes.setText(txtDescontoItem.getText());
        txtValorNf.setText(txtTotalNotaItem.getText());
    }

    public void adicionaItemPedido() {
        ItemNotaFiscalEntradaBean itemPedido = new ItemNotaFiscalEntradaBean();
        itemPedido.setCodigoProduto(((ProdutoBean) cbProduto.getSelectedItem()).getCodigo());
        itemPedido.setPrecoUnitario(Double.parseDouble(txtValorUnitarioItem.getText().replace(",", ".")));
        itemPedido.setQuantidade(Double.parseDouble(txtQtdeItem.getText().replace(",", ".")));
        itemPedido.setPrecoTotalItem(Double.parseDouble(txtTotalItem.getText().replace(",", ".")));
        itemPedido.setCodigoItem(++item);
        itemPedido.setPrecoTotalNotaFiscalItem(Double.parseDouble(txtTotalNotaItem.getText().replace(",", ".")));
        itemPedido.setItemProdutoBean((ProdutoBean) cbProduto.getSelectedItem());
        itemPedido.setValotDesconto((txtDescontoItem.getText().isEmpty() ? 0 : Double.parseDouble(txtDescontoItem.getText().replace(",", "."))));
        itemPedido.setRefItemProduto(txtRefProdItem.getText());

        listaDeItens.add(itemPedido);
    }

    public void calculaTotalItem() {
        if (!txtQtdeItem.getText().isEmpty() && !txtValorUnitarioItem.getText().isEmpty()) {
            txtTotalItem.setText(decimalFormato.format(Double.parseDouble(txtValorUnitarioItem.getText().replace(",", ".")) * Double.parseDouble(txtQtdeItem.getText().replace(",", "."))));
            txtTotalNotaItem.setText(decimalFormato.format(Double.parseDouble(txtValorUnitarioItem.getText().replace(",", ".")) * Double.parseDouble(txtQtdeItem.getText().replace(",", "."))));
        }
    }

    public void calculaTotalNotaItem() {
        if (!txtQtdeItem.getText().isEmpty() && !txtValorUnitarioItem.getText().isEmpty()) {
            txtTotalItem.setText(decimalFormato.format(Double.parseDouble(txtValorUnitarioItem.getText().replace(",", ".")) * Double.parseDouble(txtQtdeItem.getText().replace(",", "."))));
        }

    }

    public void limpaCamposItens() {
        txtDescontoItem.setText("");
        txtQtdeItem.setText("");
        txtRefProdItem.setText("");
        txtTotalItem.setText("");
        txtUnidadeItem.setText("");
        txtValorUnitarioItem.setText("");
        txtTotalNotaItem.setText("");

    }

    public void validaCNPJCPF() {
        if (ValidaCNPJ.isCNPJ(txtCNPJ.getText())) {
            txtCNPJ.setText(ValidaCNPJ.imprimeCNPJ(txtCNPJ.getText()));
        } else if (ValidaCPF.isCPF(txtCNPJ.getText())) {
            txtCNPJ.setText(ValidaCPF.imprimeCPF(txtCNPJ.getText()));
        }

    }

    public void pesquisaProdutos(int codigo, List<ProdutoBean> listaDeItens) {
        try {
            String SQLPesquisa = "SELECT \n"
                    + "  t.`tprd_id`,\n"
                    + "  t.`tprd_descr`,\n"
                    + "  p.`prd_prod`,\n"
                    + "  p.`prd_prod_venda`,\n"
                    + "  p.`prd_descr`,\n"
                    + "  p.`prd_unid_med`,\n"
                    + "  p.`prod_estocavel`\n "
                    //                    + "  c.`sdoe_qtd_sdo_atu` \n"
                    + "FROM\n"
                    + "  `pizzaria`.`tipo_prod` t \n"
                    + "  JOIN `pizzaria`.`produtos` p \n"
                    + "    ON p.`prd_tipo_prod`=t.tprd_id \n"
                    //                     + "  JOIN `pizzaria`.`saldo_estoque` c \n"
                    //                    + "    ON c.sdoe_cod_prod = p.prd_prod \n"
                    + "WHERE t.`tprd_id` = '" + codigo + "' and p.`prod_estocavel` ='S';";

            PreparedStatement pstmt = ConectaBanco.getConnection().prepareStatement(SQLPesquisa);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                ProdutoBean novo = new ProdutoBean();
                novo.setCodigo(rs.getInt("prd_prod"));
                novo.setDescricao(rs.getString("prd_descr"));
                novo.getTipoProduto().setCodigo(rs.getInt("tprd_id"));
                novo.getTipoProduto().setDescricao(rs.getString("tprd_descr"));
                novo.setEstocavel(rs.getString("prod_estocavel").charAt(0));
                novo.setUnidadeMedida(rs.getString("prd_unid_med"));

                listaDeItens.add(novo);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PedidoModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public boolean validaCamposNotaFiscal() {

        if (txtDtemissao.getText().equals("  /  /    ")) {
            JOptionPane.showMessageDialog(null, "Campo Data da emissão não pode ser vazio!");
            txtDtemissao.requestFocus();
            return false;
        }
        if (txtCNPJ.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Campo CNPJ não pode ser vazio!");
            txtCNPJ.requestFocus();
            return false;
        }

        if (txtTotal.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Adicione pelo menos um Item na Compra");
            return false;
        }
        if (txtValorNf.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Erro de Preenchimento!");
            return false;
        }

        return true;
    }

    private boolean cadastraPedido() {

        String tp = "";

        //  FornecedorBean f =new FornecedorBean();
        //JOptionPane.showMessageDialog(null,((FornecedorBean) cbFornecedor.getSelectedItem()).getCodigo());
        Date data = new Date();
        SimpleDateFormat formatoData = new SimpleDateFormat("yyyy-MM-dd");
        try {
            String SQLInserePedido = "INSERT INTO `pizzaria`.`ped_compra`\n"
                    + "            (`pedc_data`,\n"
                    + "             `pedc_vlr_tot`,\n"
                    + "             `pedc_vlr_desc`,\n"
                    + "             `pedc_cod_fornec`,\n"
                    + "             `pedc_id_usuario`,\n"
                    + "             `pedc_tp_ped_cotacao`,\n"
                    //+ "             `pedc_situacao`,\n"
                    //+ "             `pedc_dt_entrega`,\n"
                    + "             `pedc_forma_pagto`,\n"
                    + "             `pedc_cond_pagto`, \n"
                    + "  `pedc_vlr_liq`, \n"
                    + "             `pedc_obs`)\n"
                    + " VALUES (?,\n"
                    + "        ?,\n"
                    + "        ?,\n"
                    + "        ?,\n"
                    + "        ?,\n"
                    + "        ?,\n"
                    // + "        'pedc_situacao',\n"
                    //+ "        'pedc_dt_entrega',\n"  
                    + "        ?,\n"
                    + "        ?,\n"
                    + "        ?,\n"
                    + "        ?\n);";
            PreparedStatement pstmt = ConectaBanco.getConnection().prepareStatement(SQLInserePedido);

            // pstmt.setInt(1, ((FornecedorBean) cbFornecedor.getSelectedItem()).getCodigo());
            pstmt.setString(1, formatoData.format(data));
            pstmt.setDouble(2, (txtTotal.getText().isEmpty() ? 0 : Double.parseDouble(txtTotal.getText())));//assim?
            pstmt.setDouble(3, (txtValorDes.getText().isEmpty() ? 0 : Double.parseDouble(txtValorDes.getText())));//da um erro aqui ...eu até dei uma olhada no banco ...e está como decima ai usei o Double certo né?ok
            pstmt.setInt(4, ((FornecedorBean) cbFornecedor.getSelectedItem()).getCodigo());
            pstmt.setString(5, Global.usuario.getLogin());
            if (jtipoPedido.getSelectedItem().equals("Pedido")) {

                tp = "P";

            } else {

                tp = "C";

            }
            pstmt.setString(6, tp);
            pstmt.setString(7, jFormaPagamento.getSelectedItem().toString());
            pstmt.setString(8, jCondPagamento.getSelectedItem().toString());//não tem nada nesse combo!ok 
            pstmt.setString(10, txtObs.getText());
            pstmt.setDouble(9, (txtValorNf.getText().isEmpty() ? 0 : Double.parseDouble(txtValorNf.getText())));//assim?
            pstmt.execute();

            if (cadastrarItens()) {
                ConectaBanco.getConnection().commit();
                JOptionPane.showMessageDialog(null, "Pedido realizado com sucesso", "Cadastro efetivado", 1, new ImageIcon("imagens/ticado.png"));
                return true;
            } else {
                ConectaBanco.closeConnection();
                return false;
            }
        } catch (SQLException ex) {
            try {
                ConectaBanco.getConnection().rollback();
                JOptionPane.showMessageDialog(null, "Impossível Cadastrar Pedido" + ex, "Erro de SQL", 0, new ImageIcon("imagens/cancelar.png"));
            } catch (SQLException ex1) {
                Logger.getLogger(PedidoModel.class.getName()).log(Level.SEVERE, null, ex1);
            }
            return false;

        }

    }

    public boolean cadastrarItens() {

        for (int i = 0; i < listaDeItens.size(); i++) {//toda vez que apertar no botão acionar grava um item nessa lista listaDeItens aqui voce varre ela e popula o banco blz man...vai lá dormir vou me virar kkk já ajudou pra carambaboa sorte e boa naoite...ja ja eu levanto man....04:30puts fui falo mano dorme Com Deus nós Amém
            try {

                String SQLInsertItens = "insert into `pizzaria`.`item_ped_compra` (\n"//os itens do pedido ok
                        + "  `pedci_cod_ped`,\n"//código do pedido aqui falta 
                        // + "  `pedci_item`,\n"
                        + "  `pedci_cod_prod`,\n"
                        + "  `pedci_qtde`,\n"
                        + "  `pedci_vlr_unit`,\n"
                        + "  `pedci_vlr_desc`,\n"
                        + "  `pedci_vlr_tot`,\n"
                        + "  `pedci_cod_ref_prod`,\n"
                        +" `pedci_vlr_liq`, "
                        + "  `pedci_situacao`\n"
                        + ") "
                        + "values (?,\n"
                        //  + "        ?,\n"
                        + "        ?,\n"
                        + "        ?,\n"
                        + "        ?,\n"
                        + "        ?,\n"
                        + "        ?,\n"
                        + "        ?,\n"
                        + "        ?,\n"
                        + "       ?);";

                PreparedStatement pstmt = ConectaBanco.getConnection().prepareStatement(SQLInsertItens);
                pstmt.setInt(1, codigoDoPedido());
               // pstmt.setInt(2, Integer.parseInt(txtSerie.getText()));
                // pstmt.setInt(2, ((FornecedorBean) cbFornecedor.getSelectedItem()).getCodigo());
                // pstmt.setInt(2,2);
                pstmt.setInt(2, listaDeItens.get(i).getCodigoProduto());
                pstmt.setDouble(3, listaDeItens.get(i).getQuantidade());
                pstmt.setDouble(4, listaDeItens.get(i).getPrecoUnitario());
                pstmt.setDouble(5, listaDeItens.get(i).getValotDesconto());
                pstmt.setDouble(8, listaDeItens.get(i).getPrecoTotalNotaFiscalItem());
                pstmt.setString(7, listaDeItens.get(i).getRefItemProduto());
                pstmt.setDouble(6, listaDeItens.get(i).getPrecoTotalItem());

                pstmt.setString(9, "P");
                pstmt.execute();

            } catch (SQLException ex) {
                Logger.getLogger(PedidoModel.class.getName()).log(Level.SEVERE, null, ex);
                try {
                    ConectaBanco.getConnection().rollback();
                    JOptionPane.showMessageDialog(null, "Impossível Cadastrar Item" + ex, "Erro de SQL", 0, new ImageIcon("imagens/cancelar.png"));

                } catch (SQLException ex1) {
                    Logger.getLogger(PedidoModel.class.getName()).log(Level.SEVERE, null, ex1);
                }
                return false;
            }
        }

        return true;
    }

    public int codigoDoPedido() {
        int codigo = 1;

        try {
            String SQLSelection = "select pedc_cod from ped_compra order by pedc_cod desc limit 1";

            PreparedStatement pstmt = ConectaBanco.getConnection().prepareStatement(SQLSelection);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                codigo = rs.getInt("pedc_cod");
            }

        } catch (SQLException ex) {
            Logger.getLogger(PedidoModel.class.getName()).log(Level.SEVERE, null, ex);
        }
        //JOptionPane.showMessageDialog(null, codigo);
        return codigo;
    }

}
